package com.lwq.cocos;

import java.awt.Graphics;
import java.awt.Image;

import com.google.gson.annotations.Expose;
import com.lwq.util.Constance;
import com.lwq.util.DrawUtil;

public class CCSprite extends CCNode {
	@Expose private String ImgPath = null;
	@Expose private String Tile = null;

	public CCSprite(String name) {
		super(name);
		setType(Constance.SPRITE_TYPE);
	}

	public String getTile() {
		return Tile;
	}

	public void setTile(String tile) {
		Tile = tile;
	}

	public void init() {
		super.init();
	}

	public String getImgPath() {
		return ImgPath;
	}

	public void setImgPath(String imgPath) {
		ImgPath = imgPath;
	}

	public void draw(Graphics g) {
		if (g == null)
			return;
		if (ImgPath != null && mVisible) {
			Image mImage = ImageContainer.getInstance().getImage(ImgPath);
			if (mImage != null) {
				int width = (int) (mImage.getWidth(null) * mScaleX);
				int height = (int) (mImage.getHeight(null) * mScaleY);
				int paintPosX = 0;
				int paintPosY = 0;
				float anchorVals[] = Constance.getAnchorScaleValue(mAnchor);
				if (anchorVals != null) {
					paintPosX = (int) (getLocPosX() - width * anchorVals[0]);
					paintPosY = (int) (getLocPosY() - height * anchorVals[1]);
				} else {
					paintPosX = (int) (getLocPosX());
					paintPosY = (int) (getLocPosY());
				}
				DrawUtil.drawImageRotate(g, mImage, paintPosX, paintPosY,
						width, height, mRotate);
			}
		}
		super.draw(g);
	}

}
